import { StorageKey, OtherKey } from '../common/Key';
import { MaxLevel } from './GameDefine';
export const GameData = {
    level: 0,
    maxLevel: 0,

    succMode: false,

    getLocalLevel() {
        // this.level = 25;
        // return;
        this.level = G.data.getItem(StorageKey.GAME_LEVEL, 0);
        this.maxLevel = G.data.getItem(StorageKey.MAX_LEVEL, this.level);
    },

    resetLevel() {
        this.level = 0;
        G.data.setItem(StorageKey.GAME_LEVEL, this.level);
    },

    addLevel() {
        this.level++;
        if (this.level > MaxLevel) {
            this.level = GameData.MaxLevel
            return false;
        }
        G.data.setItem(StorageKey.GAME_LEVEL, this.level);
        this._updateMaxLevel();
        this.subScore({ score: this.maxLevel });
        G.partner.sendEvent('关卡', { '类型': this.level });
        return true;
    },
    subLevel() {
        this.level--;
    },

    _updateMaxLevel() {
        if (this.level > this.maxLevel) {
            this.maxLevel = this.level;
            G.data.setItem(StorageKey.MAX_LEVEL, this.maxLevel);
        }
    },

    subScore(score) {
        G.partner.setUserCloudStorage(OtherKey.kRecord, score);
    },
}